package com.wuh.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuh.mapper.LinkMapper;
import com.wuh.mapper.TeacherMapper;
import com.wuh.model.Link;
import com.wuh.service.LinkService;


@Service
public class LinkImpl implements LinkService {

	@Autowired
    private LinkMapper linkMapper;
	

	@Override
	public PageInfo<Link> getLinks(Link link) {
		// TODO Auto-generated method stub
		PageHelper.startPage(link.getPageNum(), link.getPageSize());
		List<Link> list = linkMapper.getLinks(link);
		PageInfo<Link> pageInfo = new PageInfo<Link>(list);
		
		System.out.println(pageInfo);
		return pageInfo;
	}


	@Override
	@Transactional //事务注解
	public int delLinks(Integer[] ids) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		int flag = 0;
		for(Integer id : ids) {
			flag = linkMapper.delLinkById(id);
		}
		
		return flag;
	}


	@Override
	public int addLink(Link link) {
		// TODO Auto-generated method stub
		link.setLink_url("https://"+link.getLink_url());
		link.setCreate_time(new Date());
		return linkMapper.addLink(link);
	}


	@Override
	public List<Link> getAllLinks(Link link) {
		// TODO Auto-generated method stub
		return linkMapper.getAllLinks(link);
	}
}
